".$task['title']." ";
echo "".$task['description']." ";
echo "".$user['user_name']." ";
echo "";
if (!$task['billable']) { echo $task['hours']; } else { echo "".$task['hours']." "; }
echo "";
if ($task[comments]) {
echo " ";
} else {
echo " ";
}
if ($task['status'] == "$status") {
if ($status==1) {
if (get_children($task['task_id'],1)) {
echo " "
." ";
} else {
echo " "
." ";
}
} else {
if (get_children($task[task_id],0)) {
echo " "
." ";
} else {
echo " "
." ";
}
}
} else {
echo " "
." ";
}
}
print_tree($task['task_id'], 0, $status);
}
}
}
function print_tree($task_id, $count, $status) {
global $locale,$id;
$count++;
$indent = $count*10;
$result = get_children($task_id, 2);
for ($x=0; $x".$spazio;
echo "".$task['title']." ";
echo "".$task['description']." ";
echo "".$todouser['user_name']." ";
echo "";
if (!$task['billable']) { echo $task['hours']; } else { echo "".$task['hours']." "; }
echo " ";
if ($task[comments]) {
echo " ";
} else {
echo " ";
}
if ($task['status'] == "$status") {
if ($status==1) {
if (get_children($task['task_id'],1)) {
echo " "
." ";
} else {
echo " "
." ";
}
} else {
if (get_children($task['task_id'],0)) {
echo " "
." ";
} else {
echo " "
." ";
}
}
} else {
echo " "
." ";
}
print_tree($result[$x][0], $count, $status);
}
}
}
function get_children($task_id, $status) {
// returns the task_id's of all child tasks that are status=$status
$count = 0;
if (($status == 0) || ($status == 1)) { $query = " parent_id='$task_id' AND status='$status'"; }
else { $query = " parent_id='$task_id'"; }
$result = dbquery("SELECT task_id FROM ".DB_PREFIX."prj_tasks WHERE".$query);
while ($row = dbarray($result)) {
$children[$count][0] = $row["task_id"];
$count++;
}
return $children;
}
function get_decendents($task_id, $status, $count = 0) {
$result = get_children($task_id, 2);
for ($x=0; $x".$task['title']."\n";
print_task_dropdown($task['task_id'], 0);
}
}
}
function print_task_dropdown($task_id, $count) {
global $id;
$count++;
$indent=$count*3;
$spacing="";
for ($x=0; $x<$indent; $x++) { $spacing.=" "; }
$result = get_children($task_id, 2);
for ($x=0; $x$spacing $task[title]";
print_task_dropdown($result[$x][0], $count);
}
}
function get_user_info($id) {
$result = dbquery("SELECT * FROM ".DB_PREFIX."users WHERE id='$id'");
while ($row = dbarray($result)) {
$info["user_id"] = $id;
$info["user_name"] = $row["user_name"];
$info["user_password"] = $row["user_password"];
$info["user_email"] = $row["user_email"];
$info["role"] = $row["user_level"];
}
return $info;
}
// ************************************************************
// *** TASK RELATED FUNCTIONS ***
// ************************************************************
function mytasks() {
global $finish,$userdata, $locale;
// If a task was flagged for finishing then do it now
$user_id = $userdata['user_id'];
if (isset($finish)) { finishtask($finish); }
$result2 = dbquery("SELECT * FROM ".DB_PREFIX."prj_tasks WHERE person='$user_id' AND status='1' GROUP BY 'id'");
if ( dbrows($result2) > 0 ) {
while ($open = dbarray($result2)) {
echo "";
$result3 = dbquery("SELECT * FROM ".DB_PREFIX."prj_projects WHERE id='$open[id]'");
while ($project = dbarray($result3)) {
echo "";
echo "".$locale['apm516']." ";
echo " ".$project['name']." ";
echo "\n";
echo "";
echo " ";
echo " ";
echo "";
echo "";
echo " \n";
echo " ";
echo "";
echo "";
echo " \n";
echo " ";
echo "".$locale['apm504']." ";
echo "".$project['comments']." ";
echo "".$locale['apm535']." ";
echo "",prettydate($project['startdate'])," ";
echo "".$locale['apm531']." ";
echo "",prettydate($project[enddate])," ";
echo "Status ";
echo "",draw_time_and_progress_bars($project['id'], 4)," ";
echo "
";
tablebreak();
echo "";
echo "";
echo "".$locale['apm501']." ";
echo "".$locale['apm503']." ";
echo "".$locale['apm504']." ";
echo "".$locale['apm505']." ";
echo " ";
$result4 = dbquery("SELECT * FROM ".DB_PREFIX."prj_tasks WHERE person='".$user_id."' AND status='1' AND id='".$project['id']."' ORDER BY 'hours' DESC");
while ($task = dbarray($result4)) {
echo "";
if (!$task[billable]) { echo $task[hours]; } else { echo "".$task[hours]." "; }
echo "".$task[title]." ";
echo "".nl2br($task[description])." ";
echo "";
if ($task[comments]) { echo " "; } else { echo " "; }
echo " ";
echo " ";
echo " ";
}
echo "";
echo "".$locale['apm513']." ";
echo "
";
}
}
} else { listprojects(); }
}
function addtask($id, $name) {
global $message,$locale;
$result = dbquery("SELECT * FROM ".DB_PREFIX."prj_projects WHERE id=$id");
$add = dbarray($result);
$result2 = dbquery("SELECT * FROM ".DB_PREFIX."users");
$result3 = dbquery("SELECT task_id, title FROM ".DB_PREFIX."prj_tasks WHERE id=$id");
echo "\n";
tablebreak();
}
function addtaskaction($id, $name, $title, $hours, $description, $person, $notify, $billable, $parent_id) {
global $locale,$settings;
$address = dbarray(dbquery("SELECT * FROM ".DB_PREFIX."users WHERE user_id='$person'"));
$project = dbarray(dbquery("SELECT * FROM ".DB_PREFIX."prj_projects WHERE id='$id'"));
$enddate = $project['enddate'];
$result = dbquery("INSERT INTO ".DB_PREFIX."prj_tasks VALUES ('', '$id', '$title', '$hours', '$enddate', '$description', '1', '$person', '$billable', '0', '$parent_id')");
addtask($id, $name);
if ($notify == "1") {
$textmail = $locale['apm411']
.$locale['apm412'].$project['name']."\n"
.$locale['apm413'].$title."\n"
.$locale['apm414'].$hours."\n"
.$locale['apm415'].$description."\n"
.$locale['apm416']
.$locale['apm417'];
mail($address['user_email'], $locale['apm418'], $textmail, "From: ".$setting['siteemail'], "-f".$setting['siteemail']);
}
if ($result) { message($locale['apm409'].$title.$locale['apm410']); } else { message($locale['apm408']); }
}
function edittask($task_id) {
global $locale, $message;
if ($message) message("$message");
$result = dbquery("SELECT * FROM ".DB_PREFIX."prj_tasks WHERE task_id='".$task_id."'");
while ($edit = dbarray($result)) {
$result3 = dbquery("SELECT * FROM ".DB_PREFIX."users");
$result5 = dbquery("SELECT * FROM ".DB_PREFIX."prj_comments WHERE task_id='$task_id'");
$lstprj = dbarray(dbquery("SELECT * FROM ".DB_PREFIX."prj_projects WHERE id='$edit[id]'"));
$currentuser = dbarray(dbquery("SELECT * FROM ".DB_PREFIX."users WHERE user_id='$edit[person]'"));
echo "";
echo "";
tablebreak();
echo "\n";
echo " \n";
echo " \n";
echo " \n";
echo " \n";
if ($edit[comments]=="1") display_comments($task_id);
} // end while
tablebreak();
} // end function ...a bit confusing down here =)
function edittaskaction($task_id, $id, $title, $hours, $description, $person, $billable, $parent_id) {
global $locale;
if ($parent_id == $task_id) { $error = 1; $errortext .= $locale['apm424']; }
$children = get_children($task_id, 2);
for ($x=0; $x";
echo "".$warn.$locale['apm421'].": ".$list[title]." ? \n";
echo "";
echo "".$locale['apm108']." :: ";
echo "".$locale['apm109']." ";
echo "
\n";
}
function deletetask($task_id) {
global $id,$locale;
$result = dbquery("DELETE FROM ".DB_PREFIX."prj_tasks WHERE task_id=$task_id");
$result2 = dbquery("DELETE FROM ".DB_PREFIX."prj_tasks WHERE parent_id=$task_id");
projectdetail($id);
if ($result) { message($locale['apm422']); } else { message($locale['apm423']); }
}
// ************************************************************
// *** COMMENT RELATED FUNCTIONS ***
// ************************************************************
function addcomment($task_id) {
global $message,$locale;
if ($message) message("$message");
$task = dbarray(dbquery("SELECT * FROM ".DB_PREFIX."prj_tasks WHERE task_id='$task_id'"));
echo "\n";
tablebreak();
echo "\n";
echo " ";
echo " \n";
echo " \n";
tablebreak();
}
function addcommentaction($task_id, $comment) {
global $locale, $userdata;
$user_id = $userdata['user_id'];
$date = date("YmdHis");
$formatted_comment = addslashes($comment);
$flag_comments_on = dbquery("UPDATE ".DB_PREFIX."prj_tasks SET comments='1' WHERE task_id='$task_id'");
if (dbquery("INSERT INTO ".DB_PREFIX."prj_comments VALUES (NULL,'$task_id','$user_id','$date','$formatted_comment')")) {
$message = $locale['apm618'];
} else {
$message = $locale['apm619'];
}
edittask($task_id);
}
function editcomment($comment_id, $task_id) {
global $userdata,$locale,$message;
$user_id = $userdata[user_id];
$result = dbquery("SELECT user,comment FROM ".DB_PREFIX."prj_comments WHERE comment_id='$comment_id'");
if ($owner = dbarray($result)) {
$auth_user = $owner[user];
$formatted_comment=str_replace(" ", "\n", $owner[comment]);
$formatted_comment=stripslashes($formatted_comment);
}
$result = dbquery("SELECT * FROM ".DB_PREFIX."users WHERE user_id='$user_id'");
if ( $user = dbarray($result)) {
$current_user_id = $user_id;
$current_user = $user['user_name'];
$current_role = $user["user_level"];
}
if (( $auth_user == $current_user_id) || ($current_role >= "102")) {
echo "\n";
echo "\n";
echo " \n";
echo " \n";
echo " \n";
echo " \n";
} else {
$message = $locale['apm607'];
edittask($task_id);
}
}
function editcommentaction($comment_id, $comment, $task_id) {
global $userdata,$locale;
$user_id = $userdata[user_id];
$result = dbquery("SELECT * FROM ".DB_PREFIX."prj_comments WHERE comment_id='$comment_id'");
if ($owner = dbarray($result)) { $auth_user = $owner['user']; }
$result = dbquery("SELECT * FROM ".DB_PREFIX."users WHERE user_id='$user_id'");
if ( $user = dbarray($result)) {
$current_user_id = $user['user_id'];
$current_user = $user['user_name'];
$current_role = $user["user_level"];
}
if (( $auth_user == $current_user_id) || ($current_role >= "102")) {
$date = date("M j, Y - h:i:s A");
$formatted_comment = addslashes($comment);
$formatted_comment .= " ".$locale['apm613'].$current_user." -- [".$date."] ";
if (mysql_query("UPDATE ".DB_PREFIX."prj_comments SET comment='$formatted_comment' WHERE comment_id='$comment_id'")) {
$message = $locale['apm605'];
} else {
$message = $locale['apm606'];
}
edittask($task_id);
} else {
$message = $locale['apm604'];
edittask($task_id);
}
}
function deletecomment($comment_id, $task_id) {
global $userdata,$locale,$message;
$user_id = $userdata[user_id];
$result = dbquery("SELECT user,comment FROM ".DB_PREFIX."prj_comments WHERE comment_id='$comment_id'");
if ($owner = dbarray($result)) {
$auth_user = $owner[user];
$formatted_comment=str_replace(" ", "\n", $owner[comment]);
$formatted_comment=stripslashes($formatted_comment);
}
$result = dbquery("SELECT * FROM ".DB_PREFIX."users WHERE user_id='$user_id'");
if ( $user = dbarray($result)) {
$current_user_id = $user_id;
$current_user = $user['user_name'];
$current_role = $user["user_level"];
}
if (( $auth_user == $current_user_id) || ($current_role >= "102")) {
$message = $locale['apm605']." "
."".$locale['apm108']." "
."".$locale['apm109']." ";
message($message);
} else {
$message = $locale['apm613'];
edittask($task_id);
}
}
function deletecommentaction($comment_id, $task_id) {
global $userdata,$locale,$message;
$user_id = $userdata[user_id];
$result = dbquery("SELECT * FROM ".DB_PREFIX."prj_comments WHERE comment_id='$comment_id'");
if ($owner = dbarray($result)) {
$auth_user = $owner[user];
$formatted_comment = str_replace(" ", "\n", $owner[comment]);
$formatted_comment = stripslashes($formatted_comment);
}
$result = dbquery("SELECT * FROM ".DB_PREFIX."users WHERE user_id='$user_id'");
if ( $user = dbarray($result)) {
$current_user_id = $user['user_id'];
$current_user = $user['user_name'];
$current_role = $user["user_level"];
}
if (($auth_user == $current_user) || ($current_role >="102")) {
if (dbquery("DELETE FROM ".DB_PREFIX."prj_comments WHERE comment_id='$comment_id'")) {
$message = $locale['apm611'];
} else {
$message = $locale['apm612'];
}
$result = dbquery("SELECT comment_id FROM ".DB_PREFIX."prj_comments WHERE task_id='$task_id'");
if (!$list = dbarray($result)) {
dbquery("UPDATE ".DB_PREFIX."prj_tasks SET comments='0' WHERE task_id='$task_id'");
}
edittask($task_id);
}
}
function display_comments($task_id) {
global $locale;
tablebreak();
tablebreak();
$result = dbquery("SELECT *,DATE_FORMAT(date,'%b %e, %Y - %r')\"formatted_date\" FROM ".DB_PREFIX."prj_comments WHERE task_id='$task_id' ORDER BY date ASC");
echo "";
echo "".$locale['apm606']." ";
echo "
\n";
while ($comments = dbarray($result)) {
$result2 = dbquery("SELECT * FROM ".DB_PREFIX."users WHERE user_id='$comments[user]'");
$name = dbarray($result2);
$formatted_comments = stripslashes(nl2br($comments[comment]));
echo "";
echo "";
echo "".$name[user_name]." ".$comments[formatted_date]." ";
echo " ";
echo " ";
echo " ".$formatted_comments." \n";
echo "
";
}
tablebreak();
}
// ************************************************************
// *** PROJECT RELATED FUNCTIONS ***
// ************************************************************
function addproject() {
global $lo_tmoisBR,$locale;
$today = date('j');
$thismonthname = date('M');
$thismonthvalue = date('n');
$thisyear = date('Y');
tablebreak();
echo "\n";
echo "\n";
echo " \n";
echo " \n";
tablebreak();
}
function addprojectaction($name, $startmonth, $startday, $startyear, $endmonth, $endday, $endyear, $comments) {
global $locale;
if ( $startmonth < 9 ) { $startmonth = "0".$startmonth; }
if ( $endmonth < 9 ) { $endmonth = "0".$endmonth; }
if ( $startday < 9 ) { $startday = "0".$startday; }
if ( $endday < 9 ) { $endday = "0".$endday; }
$startdate = "$startyear.$startmonth.$startday";
$enddate = "$endyear.$endmonth.$endday";
$Fname = addslashes("$name");
$Fcomments = addslashes("$comments");
$result = dbquery("insert into ".DB_PREFIX."prj_projects values (NULL,'$Fname','$startdate','$enddate','$Fcomments','0','0000-00-00')");
addproject();
if ($result) { message($locale['apm217'].$name.$locale['apm218']); } else { message($locale['apm513']); }
}
function confirmprojectdelete($id) {
global $locale;
$list = dbarray(dbquery("SELECT name FROM ".DB_PREFIX."prj_projects WHERE id=$id"));
echo "\n";
}
function deleteproject($id) {
global $locale;
$result1 = dbquery("delete FROM ".DB_PREFIX."prj_projects where id=$id");
$result2 = dbquery("delete FROM ".DB_PREFIX."prj_tasks where id=$id");
listprojects();
if ($result1 && $result2) { message($locale['apm519']); } else { message($locale['apm520']); }
}
function editproject($id) {
global $locale,$lo_tmoisBR;
$list = dbarray(dbquery("SELECT * FROM ".DB_PREFIX."prj_projects where id=$id"));
$startyear = substr($list[startdate], 0, 4);
$startmonth = substr($list[startdate], 5, 2);
$startday = substr($list[startdate], 8, 2);
$endyear = substr($list[enddate], 0, 4);
$endmonth = substr($list[enddate], 5, 2);
$endday = substr($list[enddate], 8, 2);
$Uname = stripslashes($list[name]);
$Ucomments = stripslashes("$list[comments]");
echo "\n";
echo "\n";
echo " ";
echo " \n";
echo " \n";
tablebreak();
}
function editprojectaction($id, $name, $startmonth, $startday, $startyear, $endmonth, $endday, $endyear, $comments) {
global $locale;
if ( $startmonth < 9 ) { $startmonth = "0".$startmonth; }
if ( $endmonth < 9 ) { $endmonth = "0".$endmonth; }
if ( $startday < 9 ) { $startday = "0".$startday; }
if ( $endday < 9 ) { $endday = "0".$endday; }
$startdate = "$startyear-$startmonth-$startday";
$enddate = "$endyear-$endmonth-$endday";
$Fname = addslashes("$name");
$Fcomments = addslashes("$comments");
$result = dbquery("update ".DB_PREFIX."prj_projects SET name='$Fname', startdate='$startdate', enddate='$enddate', comments='$Fcomments' where id=$id");
listprojects();
$Uname = stripslashes("$name");
if ($result) { message($locale['apm537'].$Uname.$locale['apm541']); } else { message($locale['apm544']); }
}
function completedlist() {
global $order;
$listresult = dbquery("SELECT * FROM ".DB_PREFIX."prj_projects WHERE completed='1' ORDER BY completed_date ASC");
echo "";
echo "".$locale['apm516']." \n";
echo "".$locale['apm515']." ";
echo "".$locale['apm505']." ";
$color=true;
while ($list_row = dbarray($listresult)) {
echo "".$list_row[name]." ";
echo "".$todoitem;
echo prettydate($list_row[completed_date]);
echo " ";
echo "\n";
echo "";
echo " ";
echo " ";
echo "\n";
echo "";
echo " ";
echo " ";
echo "\n";
echo "";
echo " ";
echo " ";
}
echo "
";
tablebreak();
}
function listprojects() {
global $order, $locale;
$list_query = "SELECT id, name, enddate, comments FROM ".DB_PREFIX."prj_projects WHERE completed='0' ORDER BY enddate ASC";
$listresult = mysql_query($list_query);
if ( dbrows($listresult) > 0 ) {
echo "";
echo "".$locale['apm516']." ";
echo "".$locale['apm530']." ";
echo "".$locale['apm531']." ";
echo "".$locale['apm505']." ";
$color=true;
while ($list_row = mysql_fetch_array($listresult))
{
echo "";
echo "".$list_row[name]." ".$list_row[comments]." ";
echo "",draw_time_and_progress_bars($list_row[id], "")," ";
echo "",prettydate($list_row[enddate])," ";
echo " \n";
echo " \n";
echo " \n";
echo " ";
}
echo "
";
} else { addproject(); }
}
function projectdetail($id) {
global $finish, $reset, $ordertodo, $orderdone, $locale;
if (isset($finish)) { finishtask($finish); }
if (isset($reset)) { resettask($reset); }
$list_result = dbquery("SELECT * FROM ".DB_PREFIX."prj_projects WHERE id='".$id."'");
while ($list_row = dbarray($list_result)) {
echo "";
echo "".$locale['apm516']." ";
echo " ".$list_row['name']." ";
echo "";
echo " ";
echo " ";
echo "\n";
echo " ";
echo " ";
echo "";
echo " ";
echo " ";
echo "";
echo " ";
echo " ";
echo "".$locale['apm504']." ";
echo "".$list_row['comments']." ";
echo "".$locale['apm535']." ";
echo "",prettydate($list_row['startdate'])," ";
echo "".$locale['apm531']." ";
echo "",prettydate($list_row[enddate])," ";
echo "Status ";
echo "",draw_time_and_progress_bars($list_row['id'], 5)," ";
echo "
";
tablebreak();
echo "";
echo "".$locale['apm428']." ";
echo "".$locale['apm504']." ";
echo "".$locale['apm429']." ";
echo "".$locale['apm501']." ";
echo "".$locale['apm505']." ";
echo " ";
task_list($id, 1, "person asc");
echo "".$locale['apm508']." »»»»» ";
echo " ".sprintf( "%01.2f", hours_todo($id))." ";
echo " ";
echo " ";
echo " ";
task_list($id, 0, "person asc");
echo "".$locale['apm509']." »»»»» ";
echo " ".sprintf( "%01.2f", hours_done($id))." ";
echo " ";
echo "
";
}
}
function projectsummary($id) {
global $reset, $order, $locale;
$result = dbquery("SELECT * FROM ".DB_PREFIX."prj_projects where id=$id");
while ($project = dbarray($result)) {
echo "";
echo "".$locale['apm516']." ";
echo " ".$project['name']." ";
echo "\n";
echo " ";
echo " ";
echo "";
echo " ";
echo " ";
echo "";
echo " ";
echo " ";
echo "".$locale['apm504']." ";
echo "".$project['comments']." ";
echo "".$locale['apm535']." ";
echo "",prettydate($project['startdate'])," ";
echo "".$locale['apm531']." ";
echo "",prettydate($project[enddate])," ";
echo "Status ";
echo "",draw_time_and_progress_bars($project['id'], 5)," ";
echo "";
echo "";
echo "".$locale['apm429']." ";
echo "".$locale['apm428']." ";
echo "".$locale['apm435']." ";
echo "".$locale['apm403']." ";
echo "".$locale['apm515']." \n";
$task_result = dbquery("SELECT * FROM ".DB_PREFIX."prj_tasks WHERE id=$id ORDER BY person ASC");
$total_billable = 0;
$total_hours = 0;
while ($task = dbarray($task_result)) {
$user_result = dbquery("SELECT * FROM ".DB_PREFIX."users WHERE user_id='$task[person]'");
$user = dbarray($user_result);
echo "".$user[user_name]." ";
echo "".$task[title]." ";
echo "";
if ($task[billable]) {
$total_billable = $total_billable + $task['hours'];
echo $task['hours'];
} else { echo "0.00";}
echo " ";
$total_hours = $total_hours + $task['hours'];
echo $task['hours'];
echo " ";
if ($task['status'] == 1) { echo $locale['apm702']; } else {
echo prettydate($task['enddate']);}
echo " \n";
}
echo " ".$locale['apm112']." ";
echo "".sprintf( "%01.2f", $total_billable )." ";
echo "".sprintf( "%01.2f", $total_hours)." ";
echo " \n";
echo "
\n";
echo "
\n";
}
}
function completeproject($id) {
$completed_date=date('Y-m-d');
$result = dbquery("update ".DB_PREFIX."prj_projects SET completed='1', completed_date='$completed_date' WHERE id='$id'");
listprojects();
}
function reactivateproject($id) {
$result = dbquery("update ".DB_PREFIX."prj_projects SET completed='0' WHERE id='$id'");
listprojects();
}
////////// MISCELLANEOUS FUNCTIONS ////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
function prettydate($enddate) {
global $lo_tmois;
// This function makes the date look more human readable
$endyear=substr($enddate, 0, 4);
$endmonth=substr($enddate, 5, 2);
$endday=substr($enddate, 8, 2);
echo $endday." ".$lo_tmois[$endmonth-1]." ".$endyear;
}
function hours_todo($id) {
$todohours = 0;
$result = dbquery("SELECT * FROM ".DB_PREFIX."prj_tasks WHERE id='$id' AND status=1");
while ($row = dbarray($result)) { $todohours = $todohours + $row['hours']; }
return $todohours;
}
function hours_done($id) {
$donehours = 0;
$result = dbquery("SELECT * FROM ".DB_PREFIX."prj_tasks WHERE id='$id' AND status=0");
while ($row = dbarray($result)) { $donehours = $donehours + $row['hours']; }
return $donehours;
}
function percentTimeComplete($id) {
$result = dbquery("SELECT to_days(current_date)-to_days(startdate) AS elapsed, to_days(enddate)-to_days(startdate) AS total, completed FROM ".DB_PREFIX."prj_projects WHERE id = $id");
$row = dbarray($result);
$elapsed = $row[elapsed];
$total = $row[total];
if ($total == 0) { return 100; }
else {
if ((100 * $elapsed / $total) == 0) { return 0; }
else { return sprintf("%02d", 100 * $elapsed / $total); }
}
}
function percentcomplete($id) {
$Rtodo = dbquery("SELECT * FROM ".DB_PREFIX."prj_tasks WHERE id=$id AND status=1");
$Rdone = dbquery("SELECT * FROM ".DB_PREFIX."prj_tasks WHERE id=$id AND status=0");
$totaltodo=0;
$totaldone=0;
while ($todo = dbarray($Rtodo)) { $totaltodo = $totaltodo + $todo[hours]; }
while ($done = dbarray($Rdone)) { $totaldone = $totaldone + $done[hours]; }
$totalboth=$totaltodo+$totaldone;
if ($totalboth > 0) {
$percent=100 * ($totaldone / $totalboth);
$percentdone = sprintf("%2d",$percent);
return $percentdone;
} else{ return $percenttotal; }
}
function message($message) {
tablebreak();
echo "";
echo "".$message." \n";
echo "
\n";
tablebreak();
}
function draw_time_and_progress_bars ($id, $colspan) {
global $locale;
$timedone = percentTimeComplete($id);
$workdone = percentcomplete($id);
$safe_td = max(0, min(100, $timedone));
if ($completed) { $safe_td = min(100, $safe_td); }
if ($completed || $safe_td < $workdone) { $colour = "green"; }
elseif ($timedone < 100) { $colour = "yellow"; }
else { $colour = "red"; }
if ($timedone <= 0) { $timedone = $locale['apm522']; }
elseif ($timedone >= 100) { $timedone = $locale['apm523']; }
else { $timedone = $timedone.$locale['apm525']; }
if ($workdone <= 0) { $workdone = $locale['apm521']; }
elseif ($workdone >= 100) { $workdone = $locale['apm524']; }
else { $workdone = $workdone.$locale['apm526']; }
echo "";
echo "".$timedone." ", drawbar_colour($colour,$safe_td), " \n";
echo "".$workdone." ", drawbar_colour($colour,$workdone), " \n";
echo "
";
}
function drawbar_colour ($colour, $percent) {
$percent = max(0, min(100, $percent));
$l_colour = ($percent == 0 ? "grey" : $colour);
$r_colour = ($percent == 100 ? $colour : "grey");
if ($percent == 0 ) { $percent = 1; }
if ($percent == 100) { $percent = 99; }
echo " ";
echo " ";
echo " ";
echo " \n";
}
function apm_toolbar() {
global $locale;
echo "